<script type="text/javascript">
	
function findTarget(arr, target) {
	let map = {};		// {val: index}
	let res = [];

	for(let i = 0; i < arr.length; i++) {
		if(map[target - arr[i]] != undefined) {
			res.push([map[target - arr[i]], i]);
		}
		if(!map[arr[i]]) {
			map[arr[i]] = i;
		}
	}

	return res;
}

const res = findTarget([1,2,3,4], 5)
console.log(res)

</script>